package chatroom.bean;

import java.util.Date;
import java.util.Objects;

/**
 * @Author Gong
 * @Description
 * @dATE 2022/4/22 16:54
 **/
public class LoginUser implements Comparable{
    private String username;
    private Date loginTime;

    public LoginUser(String username, Date loginTime) {
        this.username = username;
        this.loginTime = loginTime;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public Date getLoginTime() {
        return loginTime;
    }

    public void setLoginTime(Date loginTime) {
        this.loginTime = loginTime;
    }
    @Override
    public int hashCode() {
        return Objects.hash(username);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {return true;}
        if (o == null || getClass() != o.getClass()) {return false;}
        LoginUser loginUser = (LoginUser) o;
        return Objects.equals(username, loginUser.username);
    }

    //按时间进行排序
    @Override
    public int compareTo(Object o) {
        if(o instanceof  LoginUser){
            LoginUser temp = (LoginUser)o;
            if(this.getLoginTime().getTime() - temp.getLoginTime().getTime() >= 0){
                return 1;
            }else{
                return -1;
            }
        }
        return 0;
    }
}
